home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 121
/
FreelogMagazineJuilletAout2014-No121.iso
/
Outils
/
Adobe-Air
/
adobe-air_13.exe
/
[0]
/
setup.swf
/
scripts
/
mx
/
managers
/
ToolTipManagerImpl.as
< prev
Wrap
Text File
|
2014-03-27
|
22KB
|
691 lines
package mx.managers
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
import mx.controls.ToolTip;
import mx.core.ApplicationGlobals;
import mx.core.IInvalidating;
import mx.core.IToolTip;
import mx.core.IUIComponent;
import mx.core.mx_internal;
import mx.effects.EffectManager;
import mx.effects.IAbstractEffect;
import mx.events.EffectEvent;
import mx.events.ToolTipEvent;
import mx.styles.IStyleClient;
import mx.validators.IValidatorListener;
use namespace mx_internal;
public class ToolTipManagerImpl extends EventDispatcher implements IToolTipManager2
{
mx_internal static const VERSION:String = "3.0.0.0";
private static var instance:IToolTipManager2;
private var _enabled:Boolean = true;
mx_internal var isError:Boolean;
private var _showDelay:Number = 500;
private var _hideEffect:IAbstractEffect;
mx_internal var hideTimer:Timer;
private var _scrubDelay:Number = 100;
private var _toolTipClass:Class;
mx_internal var currentText:String;
mx_internal var showTimer:Timer;
private var _currentToolTip:IToolTip;
mx_internal var scrubTimer:Timer;
mx_internal var previousTarget:DisplayObject;
private var _currentTarget:DisplayObject;
private var _showEffect:IAbstractEffect;
mx_internal var initialized:Boolean = false;
private var _hideDelay:Number = 10000;
public function ToolTipManagerImpl()
{
_toolTipClass = ToolTip;
super();
if(instance)
{
throw new Error("Instance already exists.");
}
}
public static function getInstance() : IToolTipManager2
{
if(!instance)
{
instance = new ToolTipManagerImpl();
}
return instance;
}
mx_internal function systemManager_mouseDownHandler(param1:MouseEvent) : void
{
reset();
}
public function set showDelay(param1:Number) : void
{
_showDelay = param1;
}
mx_internal function hideEffectEnded() : void
{
var _loc1_:ToolTipEvent = null;
reset();
if(mx_internal::previousTarget)
{
_loc1_ = new ToolTipEvent(ToolTipEvent.TOOL_TIP_END);
_loc1_.toolTip = currentToolTip;
mx_internal::previousTarget.dispatchEvent(_loc1_);
}
}
public function set scrubDelay(param1:Number) : void
{
_scrubDelay = param1;
}
public function get currentToolTip() : IToolTip
{
return _currentToolTip;
}
private function mouseIsOver(param1:DisplayObject) : Boolean
{
if(!param1 || !param1.stage)
{
return false;
}
if(param1.stage.mouseX == 0 && param1.stage.mouseY == 0)
{
return false;
}
return param1.hitTestPoint(param1.stage.mouseX,param1.stage.mouseY,true);
}
mx_internal function toolTipMouseOutHandler(param1:MouseEvent) : void
{
checkIfTargetChanged(param1.relatedObject);
}
public function get enabled() : Boolean
{
return _enabled;
}
public function createToolTip(param1:String, param2:Number, param3:Number, param4:String = null, param5:IUIComponent = null) : IToolTip
{
var _loc6_:ToolTip = new ToolTip();
var _loc7_:ISystemManager;
(_loc7_ = !!param5 ? param5.systemManager : ApplicationGlobals.application.systemManager).toolTipChildren.addChild(_loc6_);
if(param4)
{
_loc6_.setStyle("styleName","errorTip");
_loc6_.setStyle("borderStyle",param4);
}
_loc6_.text = param1;
sizeTip(_loc6_);
_loc6_.move(param2,param3);
return _loc6_ as IToolTip;
}
mx_internal function reset() : void
{
var _loc1_:ISystemManager = null;
mx_internal::showTimer.reset();
mx_internal::hideTimer.reset();
if(currentToolTip)
{
if(showEffect || hideEffect)
{
currentToolTip.removeEventListener(EffectEvent.EFFECT_END,mx_internal::effectEndHandler);
}
EffectManager.endEffectsForTarget(currentToolTip);
_loc1_ = currentToolTip.systemManager;
_loc1_.toolTipChildren.removeChild(DisplayObject(currentToolTip));
currentToolTip = null;
mx_internal::scrubTimer.delay = scrubDelay;
mx_internal::scrubTimer.reset();
if(scrubDelay > 0)
{
mx_internal::scrubTimer.delay = scrubDelay;
mx_internal::scrubTimer.start();
}
}
}
public function get toolTipClass() : Class
{
return _toolTipClass;
}
public function set currentToolTip(param1:IToolTip) : void
{
_currentToolTip = param1;
}
private function hideImmediately(param1:DisplayObject) : void
{
checkIfTargetChanged(null);
}
mx_internal function showTip() : void
{
var _loc2_:ISystemManager = null;
var _loc1_:ToolTipEvent = new ToolTipEvent(ToolTipEvent.TOOL_TIP_SHOW);
_loc1_.toolTip = currentToolTip;
currentTarget.dispatchEvent(_loc1_);
if(mx_internal::isError)
{
currentTarget.addEventListener("change",mx_internal::changeHandler);
}
else
{
_loc2_ = getSystemManager(currentTarget);
_loc2_.addEventListener(MouseEvent.MOUSE_DOWN,mx_internal::systemManager_mouseDownHandler);
}
currentToolTip.visible = true;
if(!showEffect)
{
showEffectEnded();
}
}
mx_internal function effectEndHandler(param1:EffectEvent) : void
{
if(param1.effectInstance.effect == showEffect)
{
showEffectEnded();
}
else if(param1.effectInstance.effect == hideEffect)
{
hideEffectEnded();
}
}
public function get hideDelay() : Number
{
return _hideDelay;
}
public function get currentTarget() : DisplayObject
{
return _currentTarget;
}
mx_internal function showEffectEnded() : void
{
var _loc1_:ToolTipEvent = null;
if(hideDelay == 0)
{
hideTip();
}
else if(hideDelay < Infinity)
{
mx_internal::hideTimer.delay = hideDelay;
mx_internal::hideTimer.start();
}
if(currentTarget)
{
_loc1_ = new ToolTipEvent(ToolTipEvent.TOOL_TIP_SHOWN);
_loc1_.toolTip = currentToolTip;
currentTarget.dispatchEvent(_loc1_);
}
}
public function get hideEffect() : IAbstractEffect
{
return _hideEffect;
}
mx_internal function changeHandler(param1:Event) : void
{
reset();
}
public function set enabled(param1:Boolean) : void
{
_enabled = param1;
}
mx_internal function errorTipMouseOverHandler(param1:MouseEvent) : void
{
checkIfTargetChanged(DisplayObject(param1.target));
}
public function get showDelay() : Number
{
return _showDelay;
}
public function registerErrorString(param1:DisplayObject, param2:String, param3:String) : void
{
if(!param2 && param3)
{
param1.addEventListener(MouseEvent.MOUSE_OVER,mx_internal::errorTipMouseOverHandler);
param1.addEventListener(MouseEvent.MOUSE_OUT,mx_internal::errorTipMouseOutHandler);
if(mouseIsOver(param1))
{
showImmediately(param1);
}
}
else if(param2 && !param3)
{
param1.removeEventListener(MouseEvent.MOUSE_OVER,mx_internal::errorTipMouseOverHandler);
param1.removeEventListener(MouseEvent.MOUSE_OUT,mx_internal::errorTipMouseOutHandler);
if(mouseIsOver(param1))
{
hideImmediately(param1);
}
}
}
mx_internal function initialize() : void
{
if(!mx_internal::showTimer)
{
showTimer = new Timer(0,1);
mx_internal::showTimer.addEventListener(TimerEvent.TIMER,mx_internal::showTimer_timerHandler);
}
if(!mx_internal::hideTimer)
{
hideTimer = new Timer(0,1);
mx_internal::hideTimer.addEventListener(TimerEvent.TIMER,mx_internal::hideTimer_timerHandler);
}
if(!mx_internal::scrubTimer)
{
scrubTimer = new Timer(0,1);
}
initialized = true;
}
public function destroyToolTip(param1:IToolTip) : void
{
var _loc2_:ISystemManager = param1.systemManager;
_loc2_.toolTipChildren.removeChild(DisplayObject(param1));
}
public function get scrubDelay() : Number
{
return _scrubDelay;
}
mx_internal function checkIfTargetChanged(param1:DisplayObject) : void
{
if(!enabled)
{
return;
}
findTarget(param1);
if(currentTarget != mx_internal::previousTarget)
{
targetChanged();
previousTarget = currentTarget;
}
}
public function set toolTipClass(param1:Class) : void
{
_toolTipClass = param1;
}
private function getGlobalBounds(param1:DisplayObject) : Rectangle
{
var _loc2_:Point = new Point(0,0);
_loc2_ = param1.localToGlobal(_loc2_);
return new Rectangle(_loc2_.x,_loc2_.y,param1.width,param1.height);
}
mx_internal function positionTip() : void
{
var _loc1_:Number = NaN;
var _loc2_:Number = NaN;
var _loc5_:Rectangle = null;
var _loc6_:Point = null;
var _loc7_:IToolTip = null;
var _loc8_:Number = NaN;
var _loc9_:Number = NaN;
var _loc10_:Number = NaN;
var _loc11_:Number = NaN;
var _loc3_:Number = currentToolTip.screen.width;
var _loc4_:Number = currentToolTip.screen.height;
if(mx_internal::isError)
{
_loc1_ = (_loc5_ = getGlobalBounds(currentTarget)).right + 4;
_loc2_ = _loc5_.top - 1;
if(_loc1_ + currentToolTip.width > _loc3_)
{
_loc8_ = NaN;
_loc9_ = NaN;
_loc1_ = _loc5_.left - 2;
if(_loc1_ + currentToolTip.width + 4 > _loc3_)
{
_loc8_ = _loc3_ - _loc1_ - 4;
_loc9_ = Object(toolTipClass).maxWidth;
Object(toolTipClass).maxWidth = _loc8_;
if(currentToolTip is IStyleClient)
{
IStyleClient(currentToolTip).setStyle("borderStyle","errorTipAbove");
}
currentToolTip["text"] = currentToolTip["text"];
Object(toolTipClass).maxWidth = _loc9_;
}
else
{
if(currentToolTip is IStyleClient)
{
IStyleClient(currentToolTip).setStyle("borderStyle","errorTipAbove");
}
currentToolTip["text"] = currentToolTip["text"];
}
if(currentToolTip.height + 2 < _loc5_.top)
{
_loc2_ = _loc5_.top - (currentToolTip.height + 2);
}
else
{
_loc2_ = _loc5_.bottom + 2;
if(!isNaN(_loc8_))
{
Object(toolTipClass).maxWidth = _loc8_;
}
if(currentToolTip is IStyleClient)
{
IStyleClient(currentToolTip).setStyle("borderStyle","errorTipBelow");
}
currentToolTip["text"] = currentToolTip["text"];
if(!isNaN(_loc9_))
{
Object(toolTipClass).maxWidth = _loc9_;
}
}
}
sizeTip(currentToolTip);
_loc6_ = new Point(_loc1_,_loc2_);
_loc7_ = currentToolTip;
_loc1_ = (_loc6_ = DisplayObject(_loc7_).root.globalToLocal(_loc6_)).x;
_loc2_ = _loc6_.y;
}
else
{
_loc1_ = ApplicationGlobals.application.mouseX + 11;
_loc2_ = ApplicationGlobals.application.mouseY + 22;
_loc10_ = currentToolTip.width;
if(_loc1_ + _loc10_ > _loc3_)
{
_loc1_ = _loc3_ - _loc10_;
}
_loc11_ = currentToolTip.height;
if(_loc2_ + _loc11_ > _loc4_)
{
_loc2_ = _loc4_ - _loc11_;
}
}
currentToolTip.move(_loc1_,_loc2_);
}
mx_internal function errorTipMouseOutHandler(param1:MouseEvent) : void
{
checkIfTargetChanged(param1.relatedObject);
}
mx_internal function findTarget(param1:DisplayObject) : void
{
while(param1)
{
if(param1 is IValidatorListener)
{
currentText = IValidatorListener(param1).errorString;
if(mx_internal::currentText != null && mx_internal::currentText != "")
{
currentTarget = param1;
isError = true;
return;
}
}
if(param1 is IToolTipManagerClient)
{
currentText = IToolTipManagerClient(param1).toolTip;
if(mx_internal::currentText != null)
{
currentTarget = param1;
isError = false;
return;
}
}
param1 = param1.parent;
}
currentText = null;
currentTarget = null;
}
public function registerToolTip(param1:DisplayObject, param2:String, param3:String) : void
{
if(!param2 && param3)
{
param1.addEventListener(MouseEvent.MOUSE_OVER,mx_internal::toolTipMouseOverHandler);
param1.addEventListener(MouseEvent.MOUSE_OUT,mx_internal::toolTipMouseOutHandler);
if(mouseIsOver(param1))
{
showImmediately(param1);
}
}
else if(param2 && !param3)
{
param1.removeEventListener(MouseEvent.MOUSE_OVER,mx_internal::toolTipMouseOverHandler);
param1.removeEventListener(MouseEvent.MOUSE_OUT,mx_internal::toolTipMouseOutHandler);
if(mouseIsOver(param1))
{
hideImmediately(param1);
}
}
}
private function showImmediately(param1:DisplayObject) : void
{
var _loc2_:Number = ToolTipManager.showDelay;
ToolTipManager.showDelay = 0;
checkIfTargetChanged(param1);
ToolTipManager.showDelay = _loc2_;
}
public function set hideDelay(param1:Number) : void
{
_hideDelay = param1;
}
private function getSystemManager(param1:DisplayObject) : ISystemManager
{
return param1 is IUIComponent ? IUIComponent(param1).systemManager : null;
}
public function set currentTarget(param1:DisplayObject) : void
{
_currentTarget = param1;
}
public function sizeTip(param1:IToolTip) : void
{
if(param1 is IInvalidating)
{
IInvalidating(param1).validateNow();
}
param1.setActualSize(param1.getExplicitOrMeasuredWidth(),param1.getExplicitOrMeasuredHeight());
}
mx_internal function showTimer_timerHandler(param1:TimerEvent) : void
{
if(currentTarget)
{
createTip();
initializeTip();
positionTip();
showTip();
}
}
mx_internal function hideTimer_timerHandler(param1:TimerEvent) : void
{
hideTip();
}
public function set showEffect(param1:IAbstractEffect) : void
{
_showEffect = param1 as IAbstractEffect;
}
public function set hideEffect(param1:IAbstractEffect) : void
{
_hideEffect = param1 as IAbstractEffect;
}
mx_internal function targetChanged() : void
{
var _loc1_:ToolTipEvent = null;
if(!mx_internal::initialized)
{
initialize();
}
if(mx_internal::previousTarget && currentToolTip)
{
_loc1_ = new ToolTipEvent(ToolTipEvent.TOOL_TIP_HIDE);
_loc1_.toolTip = currentToolTip;
mx_internal::previousTarget.dispatchEvent(_loc1_);
}
reset();
if(currentTarget)
{
if(mx_internal::currentText == "")
{
return;
}
_loc1_ = new ToolTipEvent(ToolTipEvent.TOOL_TIP_START);
currentTarget.dispatchEvent(_loc1_);
if(showDelay == 0 || mx_internal::scrubTimer.running)
{
createTip();
initializeTip();
positionTip();
showTip();
}
else
{
mx_internal::showTimer.delay = showDelay;
mx_internal::showTimer.start();
}
}
}
mx_internal function initializeTip() : void
{
if(currentToolTip is ToolTip)
{
ToolTip(currentToolTip).text = mx_internal::currentText;
}
if(mx_internal::isError && currentToolTip is IStyleClient)
{
IStyleClient(currentToolTip).setStyle("styleName","errorTip");
}
sizeTip(currentToolTip);
if(currentToolTip is IStyleClient)
{
if(showEffect)
{
IStyleClient(currentToolTip).setStyle("showEffect",showEffect);
}
if(hideEffect)
{
IStyleClient(currentToolTip).setStyle("hideEffect",hideEffect);
}
}
if(showEffect || hideEffect)
{
currentToolTip.addEventListener(EffectEvent.EFFECT_END,mx_internal::effectEndHandler);
}
}
public function get showEffect() : IAbstractEffect
{
return _showEffect;
}
mx_internal function toolTipMouseOverHandler(param1:MouseEvent) : void
{
checkIfTargetChanged(DisplayObject(param1.target));
}
mx_internal function hideTip() : void
{
var _loc1_:ToolTipEvent = null;
var _loc2_:ISystemManager = null;
if(mx_internal::previousTarget)
{
_loc1_ = new ToolTipEvent(ToolTipEvent.TOOL_TIP_HIDE);
_loc1_.toolTip = currentToolTip;
mx_internal::previousTarget.dispatchEvent(_loc1_);
}
if(currentToolTip)
{
currentToolTip.visible = false;
}
if(mx_internal::isError)
{
if(currentTarget)
{
currentTarget.removeEventListener("change",mx_internal::changeHandler);
}
}
else if(mx_internal::previousTarget)
{
_loc2_ = getSystemManager(mx_internal::previousTarget);
_loc2_.removeEventListener(MouseEvent.MOUSE_DOWN,mx_internal::systemManager_mouseDownHandler);
}
if(!hideEffect)
{
hideEffectEnded();
}
}
mx_internal function createTip() : void
{
var _loc1_:ToolTipEvent = new ToolTipEvent(ToolTipEvent.TOOL_TIP_CREATE);
currentTarget.dispatchEvent(_loc1_);
if(_loc1_.toolTip)
{
currentToolTip = _loc1_.toolTip;
}
else
{
currentToolTip = new toolTipClass();
}
currentToolTip.visible = false;
var _loc2_:ISystemManager = getSystemManager(currentTarget);
_loc2_.toolTipChildren.addChild(DisplayObject(currentToolTip));
}
}
}